package com.gxa.user.recycling.service.impl;

import com.gxa.core.recycling.pojo.CommunityManage;
import com.gxa.core.recycling.pojo.ServiceAddress;
import com.gxa.core.recycling.pojo.User;
import com.gxa.user.recycling.service.CommunityManagesService;
import com.gxa.user.recycling.service.KeepAddressService;
import com.gxa.user.recycling.service.ServiceAddressService;
import com.gxa.user.recycling.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("keepAddressService")
@Transactional(rollbackFor = {Throwable.class})
public class KeepAddressServiceImpl implements KeepAddressService {
    @Autowired
    UsersService usersService;
    @Autowired
    CommunityManagesService communityManagesService;
    @Autowired
    ServiceAddressService serviceAddressService;


    @Override
    public Long addaddress(Long id, String name, String phone,Long aid, String daddress) {
        User user = usersService.selectById(id);
        String name1 = user.getName();
        String phone1 = user.getPhone();
        if(name1==null){
            usersService.uodateName(id, name);
        }
        if(phone1==null){
            usersService.updatePhone(id,phone);
        }
        ServiceAddress serviceAddress = new ServiceAddress();
        serviceAddress.setUid(id);
        serviceAddress.setCommnuityId(aid);
        serviceAddress.setDaddress(daddress);
        serviceAddress.setHarvestName(name);
        serviceAddress.setHarvestPhone(phone);
        serviceAddressService.insert(serviceAddress);
        return serviceAddress.getId();
    }
}
